package com.day13_Internet;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @ClassName: TCP_receive_demo
 * @Author: zw
 * @Description: 出百万拳，行万里路；
 * @Create 2024/3/24-20:06
 * @Version 1.0
 */
public class TCP_receive_demo {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(4000);
        // 创建好服务Scoket对象好，首先要监听来自客户端的连接
        Socket accept = serverSocket.accept();
        // 只有监听到后才能接受数据
        InputStream inputStream = accept.getInputStream();
        byte[] bys = new byte[1024];
        int len = inputStream.read(bys);
        String data = new String(bys, 0, len);
        System.out.println("服务器接受到的数据是："+data);
        serverSocket.close();
    }
}
